package com.example.fw;

import org.openqa.selenium.By;

import com.example.tests.ContactData;

public class ContactHelper extends HelperBase{

	public ContactHelper(ApplicationManager manager) {
		super(manager);
	}

	public void initContactCreation() {
		click(By.linkText("add new"));
	}
	
	public void initContactModification () {
		click(By.xpath("//*[@id='maintable']/tbody/tr[2]/td[7]/a"));
	}

	public void fillContactForm(ContactData contact, boolean hasGroupSelected) {
		type(By.name("firstname"), contact.firstname);
		type(By.name("lastname"), contact.lastname);
		type(By.name("address"), contact.address);
		type(By.name("home"), contact.hometel);
		type(By.name("mobile"), contact.mobiltel);
		type(By.name("work"), contact.worktel);
		type(By.name("email"), contact.email);
		type(By.name("email2"), contact.email2);
		selectByText(By.name("bday"), contact.bday);
		selectByText(By.name("bmonth"), contact.bmonth);
		type(By.name("byear"), contact.byear);
		if (hasGroupSelected) {
			//selectByText(By.name("new_group"), contact.group);
		} else {
			if (driver.findElements(By.name("new_group")).size() != 0) {
				throw new Error("Group selector exists in contact modification form");
			}
		}
		type(By.name("address2"), contact.addressdop);
		type(By.name("phone2"), contact.phone2);
	}

	public void submitContactCreation() {
		click(By.name("submit"));
	}
	
	public void returnToHomePage() {
		click(By.linkText("home page"));
	}

	public void submitContactModification() {
		click(By.name("update"));
	}
	
	public void deleteContact() {
		initContactModification();
		click(By.xpath("//*[@id='content']/form[2]/input[2]"));
	}		

}
